#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/sha.h>

int pbkdf2(const char* password, const unsigned char* salt, int salt_len, int iterations, int key_len, unsigned char* key) {
    const EVP_MD* md = EVP_sha256();
    return PKCS5_PBKDF2_HMAC(password, strlen(password), salt, salt_len, iterations, md, key_len, key);
}

int main() {
    const char* password = "your_password"; // 替换为实际的口令
    const unsigned char* salt = "your_salt"; // 替换为实际的盐值
    int salt_len = strlen((const char*)salt); 
    int iterations = 10000; // 迭代次数，可根据需求调整
    int key_len = 32; // 期望的密钥长度
    unsigned char key[key_len];

    if (pbkdf2(password, salt, salt_len, iterations, key_len, key) == 1) {
        printf("PBKDF2 key: ");
        for (int i = 0; i < key_len; i++) {
            printf("%02x", key[i]);
        }
        printf("\n");
    } else {
        printf("Error in PBKDF2 calculation\n");
    }
    return 0;
}
